package idv.arthur.svn;

import java.util.Collection;
import java.util.Iterator;
import java.util.Set;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNLogEntryPath;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.wc.admin.SVNEntry;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

public class GetFileRevisionHistory {

	public static void main(String[] args) throws SVNException {
		
		final String url = "http://10.144.136.56/svndps_test/dpssvn02/";
		final String relativePath = "DevOps/.settings/";
		final String fileName = "org.eclipse.wst.common.project.facet.core.xml";
		final String usr = "dpssvn02";
		final String pwd = "abcd1234";
		

		final String termPath = relativePath+fileName;
		final SVNRepository repo = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url+relativePath));
		final ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(usr,pwd);
		repo.setAuthenticationManager(authManager);
		Set<?> changedPathsSet = null;
		final long startRevision = 0;
		final long endRevision = -1; 
		final Collection<?> logEntries = repo.log( new String[] { fileName } , null, startRevision , endRevision , true , false );
		
		
		for ( Iterator entries = logEntries.iterator( ); entries.hasNext( ); ) {
			SVNLogEntry logEntry = ( SVNLogEntry ) entries.next( );
			System.out.println(logEntry.getRevision());
		}
		
        /*for ( Iterator<?> entries = logEntries.iterator( ); logEntries.hasNext( ); ) {
        	final SVNLogEntry logEntry = ( SVNLogEntry ) entries.next( );
            if ( logEntry.getChangedPaths( ).size( ) > 0 ) {
            	changedPathsSet = logEntry.getChangedPaths( ).keySet( );
                for ( Iterator<?> changedPaths = changedPathsSet.iterator( ); changedPaths.hasNext( ); ) {
                    final SVNLogEntryPath entryPath = ( SVNLogEntryPath ) logEntry.getChangedPaths( ).get( changedPaths.next( ) );
                    if ( (entryPath.getType()=='A' || entryPath.getType()=='M') && entryPath.getPath( ).indexOf(relativePath+fileName)!=-1) {
                    	System.out.println("進入IF");
                    }
                }
            }
        }*/
	}

}
